<?php defined('SYSPATH') or die('No direct script access.');

/**
 * log处理类
 * Class St_Log
 */

use Monolog\Handler\RotatingFileHandler;
use Monolog\Logger;

class St_Log
{

    /**
     * 返回日志操作类
     * @param $file
     * @param $logPath
     * @return Logger
     * User: netman
     * Date: 2023/7/12 14:04
     */
    public static function get_logger($file, $logPath = '')
    {
        $logger = new Logger('logger');
        $logPath = $logPath ? $logPath . $file : dirname(dirname(dirname(__DIR__))) . '/data/logs/' . $file;
        $logger->pushHandler(new RotatingFileHandler($logPath, 10));
        return $logger;
    }

    /**
     * 通用日志记录
     * @param $message
     * @param $content
     * @param $logFileName
     * @param $logPath
     * User: netman
     * Date: 2023/7/12 14:04
     */
    public static function write($message, $content, $logFileName='default.log', $logPath = '')
    {
        $logger = self::get_logger($logFileName, $logPath);
        if (is_array($content)) {
            $logger->info($message, $content);
        } else {
            $logger->info($message, [$content]);
        }
    }


}